def prost(a):
    t = 2
    for i in range(2,int(a** 0.5)):
        if a % i == 0:
            t += 2
        if int(a ** 0.5) ** 2 == a:
            t += 1
    if t == 2:
        return(a)

n = int(input())
if n < 1000 or n > 9999:
    print(0)
else:
    n1 = n // 1000           
    n2 = (n // 100) % 10
    n3 = (n // 10) % 10
    n4 = n % 10
    v1 = int(str(n1) + str(n2) + str(n3))
    v3 = int(str(n2) + str(n3) + str(n4))
    v2 = int(str(n1) + str(n2))
    v4 = int(str(n2) + str(n3))
    v5 = int(str(n3) + str(n4))
    if prost(n) == n:
        print(n)
        exit()
    if prost(v1) == v1:
        if prost(v3) == v3:
            print(max(v1, v3))
        else:
            print(v1)
    else:
        if prost(v3) == v3:
            print(v3)
        else:


            if prost(v2) == v2:
                if prost(v4) == v4:
                    if prost(v5) == v5:
                        print(max(v2,v4,v5))
                    else:
                        print(max(v2,v4))
                else:
                    if prost(v5) == v5:
                        print(max(v2,v5))
                    else:
                        print(v2)
            else:
                if prost(v4) == v4:
                    if prost(v5) == v5:
                        print(max(v4,v5))
                    else:
                        print(v4)
                else:
                    if prost(v5) == v5:
                        print(v5)
                    else:


                        if prost(n1) == n1:
                            if prost(n2) == n2:
                                if prost(n3) == n3:
                                    if prost(n4) == n4:
                                        print(max(n1,n2,n3,n4))
                                    else:
                                        print(max(n1,n2,n3))
                                else:
                                    if prost(n4) == n4:
                                        print(max(n1,n2,n4))
                                    else:
                                        print(max(n1,n2))
                            else:
                                if prost(n3) == n3:
                                    if prost(n4) == n4:
                                        print(max(n1,n3,n4))
                                    else:
                                        print(max(n1,n3))
                                else:
                                    if prost(n4) == n4:
                                        print(max(n1,n2,n4))
                                    else:
                                        print(max(n1,n2))
                        else:
                            if prost(n2) == n2:
                                if prost(n3) == n3:
                                    if prost(n4) == n4:
                                        print(max(n2,n3,n4))
                                    else:
                                        print(max(n2,n3))
                                else:
                                    if prost(n4) == n4:
                                        print(max(n2,n4))
                                    else:
                                        print(n2)
                            else:
                                if prost(n3) == n3:
                                    if prost(n4) == n4:
                                        print(max(n3,n4))
                                    else:
                                        print(n3)
                                else:
                                    if prost(n4) == n4:
                                        print(n4)
                                    else:
                                        print(0)
